<?php
require_once("vcl/vcl.inc.php");
require_once("lib/db_connection.php");
//Includes
use_unit("components4phpfull/jtiframe.inc.php");
use_unit("components4phpfull/jtdatepicker.inc.php");
use_unit("components4phpfull/jtsitetheme.inc.php");
use_unit("forms.inc.php");
use_unit("extctrls.inc.php");
use_unit("stdctrls.inc.php");

//Class definition
class Route_create extends Page
{
       public $edTotal = null;
       public $edStartHrs = null;
       public $Label4 = null;
       public $edStopMin = null;
       public $edStopHrs = null;
       public $edStartMin = null;
       public $Label3 = null;
       public $edHrs = null;
       public $lblHrs = null;
       public $lblStopTime = null;
       public $lblStartTime = null;
       public $hiddenEmp = null;
       public $btnCancel = null;
       public $btnSubmit = null;
       public $memoDesc = null;
       public $edmiles = null;
       public $edOdstop = null;
       public $edOdStart = null;
       public $edShift = null;
       public $cmbveh = null;
       public $JTEnd = null;
       public $JTstart = null;
       public $Label11 = null;
       public $Label10 = null;
       public $Label9 = null;
       public $Label8 = null;
       public $Label7 = null;
       public $Label6 = null;
       public $Label2 = null;
       public $Label1 = null;
       public $JTSiteTheme1 = null;
       public $Image1 = null;
       function edStopMinJSBlur($sender, $params)
       {
       echo $this->edStopMin->ajaxCall("computeHrs");
       }



       function edStopHrsJSBlur($sender, $params)
       {
       echo $this->edStopMin->ajaxCall("computeHrs");
       }


       function computeHrs($sender, $params)
       {
       $startHrs = $this->edStartHrs->Text;
       $startMin = $this->edStartMin->Text;
       $endHrs = $this->edStopHrs->Text;
       $endMin = $this->edStopMin->Text;

       $start = strtotime($startHrs." hours ".$startMin." minutes");
       $end = strtotime($endHrs." hours ".$endMin." minutes");
       $answer = $end - $start;

       $this->edTotal->Text = date('H\h i\m',$answer);
       $ansMin = date('i',$answer);
       $ansHrs = date('H',$answer);
       $compAns =($ansMin/60) + $ansHrs;
       $this->edHrs->Text = round($compAns,2);
       }




       function edTimeStopJSKeyUp($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.Route_create.edhours.value = (document.Route_create.edTimeStop.value) - (document.Route_create.edtimeStart.value);
       <?php

       }

       function edtimeStartJSKeyUp($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.Route_create.edhours.value = (document.Route_create.edTimeStop.value) - (document.Route_create.edtimeStart.value);
       <?php

       }

       function edOdstopJSKeyUp($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.Route_create.edmiles.value = (document.Route_create.edOdstop.value) - (document.Route_create.edOdStart.value);
       <?php

       }

       function edOdStartJSKeyUp($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.Route_create.edmiles.value = (document.Route_create.edOdstop.value) - (document.Route_create.edOdStart.value);
       <?php

       }

       function btnCancelClick($sender, $params)
       {
       redirect('route_list.php?emp='.$this->hiddenEmp->getValue());


       }

       function Route_createCreate($sender, $params)
       {
       $emp = $_GET['emp'];
       $this->hiddenEmp->setValue($emp);

       $this->cmbveh->Clear();
        $result_veh = mysql_query("select * from vehicle_tbl where company_id='1'");

        while($row_veh = mysql_fetch_array($result_veh))
        {
            $this->cmbveh->AddItem('Plate No:'.$row_veh['veh_num'].'  '.$row_veh['year'].''.$row_veh['manufacturer_name'].''.$row_veh['model_name'], null, $row_veh['vehicle_id']);
        }

       $this->JTstart->Date='';
       $this->JTEnd->Date='';
       $this->edTotal->Text='';
       $this->edStartHrs->Text='';
       $this->edStopMin->Text='';
       $this->edStopHrs->Text='';
       $this->edStartMin->Text='';
       $this->edHrs->Text='';
       $this->edmiles->Text='';
       $this->edOdstop->Text='';
       $this->edOdStart->Text='';
       $this->edShift->Text='';

       }

       function btnSubmitClick($sender, $params)
       {
        if($this->chkovernight->Checked==true)
       {
       $overnight = '1';
       }
       else
       {
       $overnight = '0';
       }

       $vehicle_id = $this->cmbveh->getItemIndex();
       $result_vehicle = mysql_query("SELECT * FROM vehicle_tbl WHERE vehicle_id='".$vehicle_id."'")
       or die("GET VEH_ID ".mysql_error());
       $row_veh = mysql_fetch_array($result_vehicle);


       $result = mysql_query("insert into route_tbl (company_id,
       emp_id,
       vehicle,
       veh_id,
       start_date,
       end_date,
       start_hrs,
       start_min,
       stop_hrs,
       stop_min,
       total_hrs,
       hrs,
       shift,
       odometer_start,
       odometer_stop,
       miles,
       description)

       values ('".$_SESSION['company_id']."',
       '".$this->hiddenEmp->getValue()."',
       '".$row_veh['veh_num'].' '.$row_veh['year'].''.$row_veh['manufacturer_name'].''.$row_veh['model_name']."',
       '".$this->cmbveh->getItemIndex()."',
       '".$this->JTstart->Date."',
       '".$this->JTEnd->Date."',
       '".$this->edStartHrs->Text."',
       '".$this->edStopMin->Text."',
       '".$this->edStopHrs->Text."',
       '".$this->edStopMin->Text."',
       '".$this->edHrs->Text."',
       '".$this->edTotal->Text."',
       '".$this->edShift->Text."',
       '".$this->edOdStart->Text."',
       '".$this->edOdstop->Text."',
       '".$this->edmiles->Text."',
       '".$this->memoDesc->Text."')")or die(mysql_error());

       redirect('route_list.php?emp='.$this->hiddenEmp->getValue());


       }

}

global $application;

global $Route_create;

//Creates the form
$Route_create=new Route_create($application);

//Read from resource file
$Route_create->loadResource(__FILE__);

//Shows the form
$Route_create->show();

?>